<template>
	<app-layout>
		<view class="boxBox flex align-center">
			<image class="goodsImg" :src="datas.pic_url"></image>
			<view class="goodsText flex flex-direction justify-between">
				<view class="nodetext2 goodsName">{{datas.name}}</view>
				<view class="flex">
					<view v-if="datas.give_integral -0" class="couponBox">赠券{{datas.give_integral}}</view>
				</view>
				<view class="flex align-center justify-between">
					<view>
						<text style="font-size: 22upx;color:#ff5a5a;">￥</text>
						<text class="price">{{datas.price}}</text>
					</view>
					<view style="font-size: 30upx;">
						<text>x</text>
						<text>{{datas.num}}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="boxBox">
			<view class="cItem flex align-center" @click="type = 4">
				<image class="cIcon" src="/static/image/WB/tihuo.png"></image>
				<view>提货</view>
				<image class="cImg" :src="type == 4?'../mch/static/image/apply-ok.png':'../mch/static/image/apply-er.png'"></image>
			</view>
			<view class="cItem flex align-center" @click="type = 2">
				<image class="cIcon" src="/static/image/WB/jimai.png"></image>
				<view>寄卖</view>
				<image class="cImg" :src="type == 2?'../mch/static/image/apply-ok.png':'../mch/static/image/apply-er.png'"></image>
			</view>
			<view class="cItem flex align-center" @click="type = 3">
				<image class="cIcon" src="/static/image/WB/share.png"></image>
				<view>分享好友</view>
				<image class="cImg" :src="type == 3?'../mch/static/image/apply-ok.png':'../mch/static/image/apply-er.png'"></image>
			</view>
		</view>
		<view class="sBtn" @click="postSell" v-if="!ifshare">确认选择</view>
		<view class="sBtn" @click="toshare" v-else>立即分享</view>
	</app-layout>
</template>

<script>
	export default {
		data(){
			return {
				datas:'',
				type:1,
				ifshare:false
			}
		},
		onLoad(op){
			this.datas = JSON.parse(op.datas)
			console.log(this.datas)
		},
		methods:{
			postSell(){
				this.$showLoading();
				this.$request({
				    url: this.$api.jimai.order_sale,
				    data: {
				        type: this.type,
						id:this.datas.order_id
				    }
				}).then(info => {
				    this.$hideLoading();
				    if (info.code === 0) {
						this.$showM(info.msg,false,res=>{
							if(this.type == 3){
								this.ifshare = true
								this.toshare()
							}else{
								uni.navigateBack()
							}
							
						})
				    }else{
						this.$showM(info.msg,false,res=>{
							uni.navigateBack()
						})
					}
				}).catch(info => {
				    this.$hideLoading();
				})
			},
			toshare(){
				this.$showM('寄卖成功，请点击微信“···”按	钮，分享给好友',true,res=>{
					if(!res){
						uni.navigateBack()
					}else{
						this.postShare()
					}
				})
			},
			postShare(){
				var obj = {
					title: '美试客',
					desc:this.datas.name,
					imgurl: this.datas.pic_url,
					mch_id: this.datas.mch_id,
					goods:this.datas.share_goods_id,
					type:2,
					url:'plugins/jimai/goods'
				}
				console.log(obj)
				if (this.$wx && this.$wx.isWechat()) { //检查是否是微信环境
					this.$wx.shareWX(obj,(err)=>{
						this.postShare()
					})
				}
			}
		}
	}
</script>

<style scoped>
	.sBtn{
		position: absolute;
		bottom: 100upx;
		width: 700upx;
		left: 25upx;
		line-height: 70upx;
		text-align: center;
		background-image: linear-gradient(to right,#ffce63,#ff8859);
		color: #fff;
		border-radius: 10upx;
	}
	.cIcon{
		width: 40upx;
		height: 40upx;
	}
	.cImg{
		width: 40upx;
		height: 40upx;
	}
	.cItem{
		height: 100upx;
		border-bottom: 1px solid #eee;
	}
	.cItem view{
		width:550upx;
		margin-left:20upx;
		font-size: 30upx;
	}
	.price{
		font-size: 28upx;
		font-weight: bold;
		color: #ff5a5a;
	}
	.couponBox{
		font-size: 24upx;
		line-height: 30upx;
		padding: 0 10upx;
		color:#ff5a5a;
		border: 1px solid #ff5a5a;
		border-radius: 6upx;
	}
	.goodsName{
		font-size: 28upx;
		font-weight: bold;
		line-height: 35upx;
		height: 70upx;
	}
	.goodsText{
		margin-left: 20upx;
		height: 150upx;
		width: 500upx;
	}
	.goodsImg{
		width: 140upx;
		height: 140upx;
		border-radius: 10upx;
	}
	.boxBox{
		background: #fff;
		padding: 20upx;
		border-radius: 20upx;
		margin: 30upx auto 0;
		width: 700upx;
	}
</style>
